// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <melon/init/init.h>
#include <turbo/flags/flag.h>
#include <gtest/gtest.h>
#include <unordered_set>
#include <pollux/common/memory/shared_arbitrator.h>
#include <pollux/connectors/hive/hive_connector.h>
#include <pollux/exec/memory_reclaimer.h>
#include <pollux/testing/exec/fuzzer_util.h>
#include <pollux/testing/exec/memory_arbitration_fuzzer_runner.h>
#include <pollux/testing/exec/presto_query_runner.h>
#include <pollux/plan/reference_query_runner.h>

TURBO_FLAG(int64_t,allocator_capacity, 32L << 30, "Allocator capacity in bytes.");

TURBO_DECLARE_FLAG(int64_t, arbitrator_capacity);

TURBO_FLAG(int64_t,
    seed,
    0,
    "Initial seed for random number generator used to reproduce previous "
    "results (0 means start with random seed).");

using namespace kumo::pollux::exec;

int main(int argc, char** argv) {
  ::testing::InitGoogleTest(&argc, argv);

  // Calls common init functions in the necessary order, initializing
  // singletons, installing proper signal handlers for better debugging
  // experience.
  melon::Init init(&argc, &argv);
  test::setupMemory(FLAGS_allocator_capacity, FLAGS_arbitrator_capacity);
  const size_t initialSeed = FLAGS_seed == 0 ? std::time(nullptr) : FLAGS_seed;
  return test::MemoryArbitrationFuzzerRunner::run(initialSeed);
}
